entering_list = input()
list_string = entering_list.split()
flag_wrong = False
dict_word = {
    'zero': 0,
    'one': 1,
    'two': 2,
    'three': 3,
    'four': 4,
    'five': 5,
    'six': 6,
    'seven': 7,
    'eight': 8,
    'nine': 9
}

def prime_number(a):
    if a <= 1:
        return False
    if a == 2:
        return True
    if a % 2 == 0:
        return False
    max_del = int(a ** 0.5) + 1
    for i in range(3, max_del, 2):
        if a % i == 0:
            return False
    return True

if len(list_string) != 3:
    flag_wrong = True
else:
    for word in list_string:
        if word not in dict_word:
            flag_wrong = True
            break

if flag_wrong:
    print('Wrong input')
else:
    number = int(''.join(str(dict_word[word]) for word in list_string))
    left_number = number
    right_number = number
    while True:
        if prime_number(left_number):
            print(left_number)
            break
        if prime_number(right_number):
            print(right_number)
            break
        left_number -= 1
        right_number += 1
